<?php
/**
 * Inserts a new entry into the database.
 * @author Ian Dunn <scholar42@gmail.com>
 * @version 1.0
 * @since 2013-11-20
 */
require_once 'database.php';
require_once 'table.php';
require_once 'employees.php';
require_once 'materials.php';
require_once 'machines.php';
require_once 'customer.php';

loginInfo::update_login ();

$db = new database();

$table = $_GET['type'];

?>

<html>
	<head>
		<title>Opol - Add a new <?php print "$table";?></title>
	</head>
	<body>
		<link rel="stylesheet" type="text/css" href="opol.css">
		<?php require 'menu.php' ?>
		<br>

<?php

$ent = new $table(0);

$ret = $ent->init_from_post ($_POST);
if (!$ret) {
	print "There was an error with your input.<br>\n";
} else {
	$result = $ent->insert_to_database ($db);
	if ($table == "machine" && $result) {
/*
		// If this is a machine, then a maintenance phase needs to be created.
		require_once 'order.php';
		require_once 'schedule.php';
		order::create_maint_order ($ent->id(), $db);
		schedule::do_sched ($db);
*/
	}
}
  
// Check for error.
if (!$result) {
	echo "You do not have sufficient privileges to perform this action.<br>\n";
} else {
	echo "Entry added successfully.<br>\n";
}
$db->close ();
?>
		<a href='/'>Back</a><br>
	</body>
</html>
